<!--
 * @Author: Yang Zhang
 * @Date: 2021-12-10 00:44:52
 * @LastEditors: Yang Zhang
 * @LastEditTime: 2021-12-23 15:23:34
 * @Description: 
-->
<template>
  <div class="orderdetail">
    <div class="top">
      <a-divider>
        <div class="aboutmoney">
          <div class="money">US ${{ orderdetail.order.storeCommission }}</div>
          <div class="comm">Estimated income</div>
        </div>
      </a-divider>
    </div>
    <div class="btm">
      <div class="step">
        <a-steps :current="stepnum" labelPlacement="vertical" disabled>
          <template #progressDot="{ index, status, prefixCls }">
            <div class="circle" v-if="status === 'finish'">
              <img src="@/assets/product/dui.png" />
            </div>
            <div class="circle process" v-if="status === 'process'">
              <div class="white"></div>
            </div>
            <div class="point" v-if="status === 'wait'"></div>
          </template>
          <a-step description="Place order" />
          <a-step description="Pay success" />
          <a-step description="Shipment" />
          <a-step description="Order complete" />
        </a-steps>
      </div>
      <div class="orderinfos">
        <div class="orderinfoitem">
          <div class="leftb"></div>
          <div class="left">
            <div class="info">
              <div class="item">Order id: {{ orderdetail.order.sn }}</div>
              <div class="item">Status：{{ orderdetail.order.orderStatus }}</div>
            </div>
          </div>
          <div class="right">
            <div class="title">Shipping address</div>
            <div class="maininfo">
              <div
                class="smtitle"
              >{{ orderdetail.order.consigneeLastName }}{{ orderdetail.order.consigneeFirstName }}</div>
              <div class="item">{{ orderdetail.order.consigneeMobile }}</div>
              <div
                class="item"
                v-for="(item,index) in orderdetail.order.consigneeAddressPath.split(',')"
                :key="index"
              >{{ item }}</div>
            </div>
          </div>
        </div>
        <!-- <div class="orderinfoitem" v-if="orderdetail.allowOperationVO.showLogistics"> -->
        <div class="orderinfoitem delit" v-if="orderdetail.allowOperationVO.showLogistics">
          <div class="leftb"></div>
          <div class="left">
            <div class="info logis">
              <div>
                <div class="item">Logistics information</div>
                <div class="tit">International shipping company</div>
                <div class="det">{{ delverdt.shipper }}</div>
              </div>
              <div class="tracnum">Tracking number: {{ delverdt.logisticCode }}</div>
            </div>
          </div>
          <div class="right">
            <div class="title">Details</div>
            <div class="maininfo">
              <div
                class="item"
                v-for="(item,index) in delverdt.traces"
              >{{ item.checkpoint_date }}: {{ item.tracking_detail }}</div>
            </div>
          </div>
        </div>
      </div>
      <div class="proitem" v-for="item in orderdetail.orderItems" :key="item.id">
        <div class="imgs">
          <img :src="item.image" />
        </div>
        <div class="productinfo">
          <div class="name">{{ item.goodsName }}</div>
          <div class="desc yichu">{{ item.sellingPoint }}</div>
        </div>
        <div class="statuss">
          <div class="items">
            <div class="infos">${{ item.unitPrice }}</div>
            <div class="titles">Price per unit</div>
          </div>
          <div class="items">
            <div class="infos">{{ orderdetail.order.orderStatus }}</div>
            <div class="titles">Order status</div>
          </div>
          <div class="items">
            <div class="infos">${{ item.storeCommission }}</div>
            <div class="titles">Income</div>
          </div>
        </div>
      </div>
      <div class="mainparam">
        <div class="leftpara">
          <div class="para" v-if="orderdetail.paymentMethodValue">
            <div class="labels">Payment method:</div>
            <div class="infor">{{ orderdetail.paymentMethodValue }}</div>
          </div>
          <div class="para" v-if="orderdetail.order.deliveredDate">
            <div class="labels">Date received:</div>
            <div class="infor">{{ orderdetail.order.deliveredDate }}</div>
          </div>
        </div>
        <div class="rightpra">
          <div class="para">
            <div class="labels">Product amount:</div>
            <div class="infor">US ${{ orderdetail.order.priceDetailDTO.goodsPrice }}</div>
          </div>
          <div class="para">
            <div class="labels">Shipping cost:</div>
            <div class="infor">US ${{ orderdetail.order.priceDetailDTO.freightPrice }}</div>
          </div>
          <div class="para">
            <div class="labels">Total amount:</div>
            <div class="infor">US ${{orderdetail.order.priceDetailDTO.goodsPrice}}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang='ts' setup>
import { reactive, toRefs, onBeforeMount, onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { getDeliverdt } from '../../../../api/product'
import { getOrderdetail } from '../../../../api/wallet'
import { IOrderdetail } from '../../../types'
interface DataProps { }
const router = useRouter()
const ordersn = ref('')
onBeforeMount(() => {
  initOrderdetail()
})

const orderdetail = ref({} as IOrderdetail)
interface ITrace {
  checkpoint_date: string
  checkpoint_delivery_status: string
  checkpoint_delivery_substatus: string
  location: string
  tracking_detail: string
}
interface IDet {
  logisticCode: string
  shipper: string
  traces: ITrace[]
}
const delverdt = ref({} as IDet)
const initOrderdetail = async () => {
  const sn = router.currentRoute.value.query.sn || ''
  const res = await getOrderdetail(sn)
  if (res) {
    orderdetail.value = res.result
    if (res.result.payStatusValue === '待付款') {
      stepnum.value = 1
    } else if (res.result.payStatusValue === '已付款' && res.result.orderStatusValue !== '已完成') {
      stepnum.value = 2
    } else if (res.result.deliverStatusValue === '已发货' && res.result.orderStatusValue !== '已完成') {
      stepnum.value = 3
    } else if (res.result.orderStatusValue === '已完成') {
      stepnum.value = 5
    }
  }
  // if (orderdetail.value.allowOperationVO.showLogistics) {
  if (orderdetail.value.allowOperationVO.showLogistics) {
    let sno = sn
    const dev = await getDeliverdt(sno)
    if (dev) {
      delverdt.value = dev.result
    }
  }
}


// 当前步骤
const stepnum = ref(1)

</script>
<style lang='scss' scoped>
.orderdetail {
  width: 1600px;
  min-height: 6rem;
  background-color: #fff;
  margin-top: 20px;
  padding-bottom: 100px;
  .top {
    padding: 0 44px;
  }
  .btm {
    padding: 0 40px;
    .step {
      padding: 0 206px;
      margin-bottom: 50px;
      .circle {
        width: 32px;
        height: 32px;
        background: #e60044;
        border-radius: 50%;
        color: #fff;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        margin-top: -20px;
        img {
          width: 20px;
          height: 20px;
        }
        .white {
          width: 10px;
          height: 10px;
          background: #ffffff;
          border-radius: 50%;
        }
      }
      .point {
        width: 10px;
        height: 10px;
        background: #757575;
        border-radius: 50%;
      }
    }
    .orderinfos {
      margin-bottom: 40px;
    }
    .orderinfoitem {
      width: 1514px;
      height: 227px;
      margin-top: 20px;
      display: flex;
      .leftb {
        width: 20px;
        height: 227px;
        background: #000000;
      }
      .left {
        width: 475px;
        height: 226px;
        background: RGBA(252, 252, 252, 1);
        border: 1px solid #e0e0e0;
        padding-left: 44px;
        display: flex;
        align-items: center;
        .info {
          font-size: 18px;
          font-family: PingFang SC;
          font-weight: bold;
          color: #000000;
        }
        .logis {
          height: 130px;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          .tit,
          .det {
            font-weight: normal;
          }
          .tracnum {
            font-weight: normal;
          }
        }
      }
      .right {
        flex: 1;
        border: 1px solid #e0e0e0;
        border-left: 0;
        padding-left: 67px;
        padding-top: 29px;
        .title {
          font-size: 18px;
          font-family: PingFang SC;
          font-weight: bold;
          color: #000000;
          margin-bottom: 20px;
        }
        .maininfo {
          font-size: 16px;
          font-family: Galvji;
          color: #000000;
          font-weight: normal;
          .smtitle {
            font-weight: bold;
          }
        }
      }
    }

    .delit {
      height: auto;
      .left,
      .leftb {
        height: auto;
      }
      .right {
        padding-bottom: 30px;
      }
    }
    .proitem {
      width: 1514px;
      height: 141px;
      border: 1px solid #e0e0e0;
      border-radius: 10px;
      padding: 23px;
      display: flex;
      align-items: center;
      margin-bottom: 15px;
      img {
        width: 95px;
        height: 95px;
        margin-right: 12px;
      }
      .productinfo {
        width: 369px;
        font-size: 18px;
        font-family: Galvji;
        color: #000000;
        margin-left: 10px;
        margin-right: 68px;
        .name {
          font-weight: bold;
        }
        .desc {
          width: 369px;
          height: 80px;
        }
      }
      .statuss {
        flex: 1;
        height: 70px;
        display: flex;
        .items {
          width: 33.3%;
          height: 100%;
          border-left: 1px solid #e0e0e0;
          font-family: Galvji;
          text-align: center;
          .infos {
            font-size: 22px;
            font-weight: bold;
            color: #000000;
          }
          .titles {
            font-size: 18px;
            font-weight: normal;
          }
        }
      }
    }
    .mainparam {
      width: 100%;
      display: flex;
      justify-content: space-between;
      margin-top: 30px;
      .para {
        font-size: 22px;
        font-family: Galvji;
        display: flex;
        align-items: center;
        .labels {
          font-weight: 400;
          color: #000000;
          margin-right: 1em;
        }
        .infor {
          font-weight: bolder;
        }
      }
    }
  }
  .aboutmoney {
    width: 626px;
    height: 145px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    .money {
      font-size: 30px;
      font-family: Galvji;
      font-weight: bold;
      color: #e60044;
    }
    .comm {
      font-size: 16px;
      color: rgba(0, 0, 0, 1);
      font-family: Galvji;
    }
  }
  .ant-divider-horizontal.ant-divider-with-text::before,
  .ant-divider-horizontal.ant-divider-with-text::after {
    border-top: 1px solid #e0e0e0;
  }
}
</style>
